package com.songshan.dto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author feb
 * @date 2024/6/18
 * @Description: 菜单树构建节点
 */
public class MenuNode {

  private int id;
  private int pId;
  private String text;
  private String code;
  private String uri;
  private String icon;
  private int seq;
  private String type;
  private boolean selectable;
  private List<MenuNode> nodes;
  private List<String> tags;
  private Map<String, Object> state;

  public MenuNode() {
    this.selectable = true;
    this.state = nodeState();
    this.icon = "bi bi-file-earmark-text";
  }

  public void setNodes(List<MenuNode> nodes) {
    this.nodes = nodes;
    if (nodes != null && !nodes.isEmpty()) {
      this.icon = "bi bi-folder2";
    }
  }

  public Map<String, Object> nodeState() {
    Map<String, Object> state = new HashMap<>();
    state.put("disabled", false);
    return state;
  }

  public void setNodeTags() {
    List<String> tags = new ArrayList<>();
    tags.add("<a onclick=\"addMenu(" + this.getId()
        + ")\"><span class=\"text-black bi bi-plus-lg\"></span></a>");
    tags.add(
        "<a onclick=\"delMenu(" + this.getId() + ")\"><span class=\"text-black bi bi-trash\"></a>");
    tags.add("<a onclick=\"modMenu(" + this.getId()
        + ")\"><span class=\"text-black bi bi-pencil-square\"></a>");
    this.setTags(tags);
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public int getpId() {
    return pId;
  }

  public void setpId(int pId) {
    this.pId = pId;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getUri() {
    return uri;
  }

  public void setUri(String uri) {
    this.uri = uri;
  }

  public String getIcon() {
    return icon;
  }

  public void setIcon(String icon) {
    this.icon = icon;
  }

  public int getSeq() {
    return seq;
  }

  public void setSeq(int seq) {
    this.seq = seq;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public boolean isSelectable() {
    return selectable;
  }

  public void setSelectable(boolean selectable) {
    this.selectable = selectable;
  }

  public List<MenuNode> getNodes() {
    return nodes;
  }

  public List<String> getTags() {
    return tags;
  }

  public void setTags(List<String> tags) {
    this.tags = tags;
  }

  public Map<String, Object> getState() {
    return state;
  }

  public void setState(Map<String, Object> state) {
    this.state = state;
  }
}
